package com.lenovo.agricultureServer.http.action;

import org.json.JSONException;
import org.json.JSONObject;

import com.lenovo.agricultureServer.db.DatabaseUtil;
import android.content.Context;

public class LoginAction extends BaseAction 
{
	public static final String TAG = "login";
	
	private Context context;
	public LoginAction(Context context)
	{
		this.context = context;
	}
	
	@Override
	protected String jasonPorcess(String param) 
	{
		JSONObject jsonResponse = new JSONObject();
		try 
		{
			JSONObject jsonRequest = new JSONObject(param);
			// 处理登陆请求
			String username = "";
			String password = "";
			if(jsonRequest.has("username")){
				username = jsonRequest.getString("username");
			}
			if(jsonRequest.has("password")){
				password = jsonRequest.getString("password");
			}
			if (DatabaseUtil.query(username, password,context)) {
				jsonResponse.put("result", "ok");
			} else {
				jsonResponse.put("result", "failed");
			}
			return jsonResponse.toString();
		} 
		catch (JSONException e) 
		{
			e.printStackTrace();
		}
		catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	@Override
	protected String soapPorcess(String param) {
		//TODO
		return "";
	}

}
